<template>
    <div class="app-container">
        <el-form ref="form" :model="form" label-width="160px">
            <el-form-item label="企业名称">
                <el-input v-model="form.name" :disabled="true"/>
            </el-form-item>
            <el-form-item label="认证人数">
                <el-input v-model="form.certificationPeople"/>
            </el-form-item>
            <el-form-item label="审核类型">
                <el-select v-model="form.companyCertificationType" placeholder="请选择">
                    <el-option v-for="item in options.auditType" :key="item.value" :label="item.label"
                               :value="item.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="认证范围">
                <el-input type="textarea" :rows="5" v-model="form.companyCertificationRange"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">提交</el-button>
                <el-button @click="$router.back()">返回</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import { mapGetters } from 'vuex';
    import request from '../../utils/request';

    export default {
        name: "CompanyCertificationDetailEdit",
        computed: {
            ...mapGetters([
                'options'
            ])
        },
        data () {
            return {
                form: {
                    certificationPeople: '',
                    companyCertificationType: '',
                    companyCertificationRange: '',
                },
            };
        },
        mounted () {
            request({
                url: `api/certification-detail/${this.$route.params.id}`
            }).then(res => {
                this.form = res.data;
            });
        },
        methods: {
            onSubmit () {
                console.log(this.form);
                const {certificationPeople, companyCertificationType, companyCertificationRange} = this.form;

                request({
                    url: `/api/certification-detail/edit/${this.$route.params.id}`,
                    method: 'post',
                    data: {certificationPeople, companyCertificationType, companyCertificationRange}
                }).then(() => {
                    this.$router.push({path: '/company/certification'});
                });
                this.$message('submit!');
            },
            onRegionChange (val) {
                console.log(val);
            }
        }
    };
</script>

<style scoped>

</style>
